package tool.dialog;

import assister.MathAssister;

/**indica una TextField che rileva numeri solo compresi tra un unico range di valori.
 * Se la stringa immessa dall'utente e' un numero, ma non e' compresa nel range,
 * la TextField dà comunque errore.
 * 
 * @author Koldar
 * @version 1.0 
 *
 * @param <NUMBER> indica il tipo di numero da inserire nella TextField
 */
public class JRangedNumberField<NUMBER extends Number> extends JNumberField<NUMBER>{

	private static final long serialVersionUID = -1619624386915712362L;
	/**rappresenta l'estremo inferiore dell'intervallo di valori accettati.*/
	private NUMBER inf;
	/**rappresenta l'estremo superiore dell'intervallo di valori accettati*/
	private NUMBER sup;
	/**se TRUE indica che {@link #inf} e' incluso nell'intervallo, FALSE altrimenti*/
	private boolean infincluded;
	/**se TRUE indica che {@link #sup} e' incluso nell'intervallo, FALSE altrimenti*/
	private boolean supincluded;
	
	public JRangedNumberField(Class<NUMBER> numberUsed,NUMBER inf,NUMBER sup,boolean infcinluded,boolean supincluded) {
		super(numberUsed);
		this.inf=inf;
		this.sup=sup;
		this.infincluded=infcinluded;
		this.supincluded=supincluded;
	}

	@Override
	public NUMBER getInterestedValue() {
		NUMBER value=super.getInterestedValue();
		if (value==null){
			return null;
		}
		return MathAssister.extremis((Comparable<NUMBER>)value,this.inf,this.sup,this.infincluded,this.supincluded)?value:null;
	}


	/**
	 * @return the inf. For further information see {@link #inf}
	 */
	public NUMBER getInf() {
		return inf;
	}

	/**
	 * @param inf the inf to set
	 */
	public void setInf(NUMBER inf) {
		this.inf = inf;
	}

	/**
	 * @return the sup
	 */
	public NUMBER getSup() {
		return sup;
	}

	/**
	 * @param sup the sup to set
	 */
	public void setSup(NUMBER sup) {
		this.sup = sup;
	}

	/**
	 * @return the infincluded
	 */
	public boolean isInfincluded() {
		return infincluded;
	}

	/**
	 * @param infincluded the infincluded to set
	 */
	public void setInfincluded(boolean infincluded) {
		this.infincluded = infincluded;
	}

	/**
	 * @return the supincluded
	 */
	public boolean isSupincluded() {
		return supincluded;
	}

	/**
	 * @param supincluded the supincluded to set
	 */
	public void setSupincluded(boolean supincluded) {
		this.supincluded = supincluded;
	}
	
	
	
	

}
